package com.qys.livesMall.shortVideo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qys.livesMall.framework.view.BaseQuery;
import com.qys.livesMall.shortVideo.mapper.H2ShortVideoCategoryMapper;
import com.qys.livesMall.shortVideo.model.entity.H2ShortVideoCategory;
import com.qys.livesMall.shortVideo.service.IH2ShortVideoCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 短视频 服务实现类
 * </p>
 *
 * @author dp
 * @since 2023-05-04
 */
@Service
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class H2ShortVideoCategoryServiceImpl extends ServiceImpl<H2ShortVideoCategoryMapper, H2ShortVideoCategory> implements IH2ShortVideoCategoryService {

    @Override
    public Page<H2ShortVideoCategory> page(BaseQuery queryDTO) {
        LambdaQueryWrapper<H2ShortVideoCategory> wrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(queryDTO.getName())) {
            wrapper.like(H2ShortVideoCategory::getName, queryDTO.getName());
        }
        wrapper.orderByAsc(H2ShortVideoCategory::getSort);

        return baseMapper.selectPage(new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize()), wrapper);
    }
}
